package development.socket;

import java.util.Vector;

import state.socket.DataPackage;
import state.socket.Handle;
import state.util.Hashtable;
import development.listener.Listener;

public class RequestGroupHandle extends Handle {
  private Hashtable listeners = new Hashtable();

  public void onConnectDone() {
    Vector values = listeners.elements();
    for (int i = 0; i < values.size(); i++) {
      ((Listener) values.elementAt(i)).onConnectDone();
    }
  }
  
  public void addListener(Listener listener) {
    listeners.put(listener.getKey(), listener);
  }
  
  public void removeListener(Listener listener) {
    listeners.remove(listener.getKey());
  }

  public void onConnectFail() {
    Vector values = listeners.elements();
    for (int i = 0; i < values.size(); i++) {
      ((Listener) values.elementAt(i)).onConnectFail();
    }
  }

  public void onDisconnect() {
    Vector values = listeners.elements();
    for (int i = 0; i < values.size(); i++) {
      ((Listener) values.elementAt(i)).onDisconnect();
    }
  }

  public void processPackage(DataPackage dataPackage) {
    Vector values = listeners.elements();
    for (int i = 0; i < values.size(); i++) {
      ((Listener) values.elementAt(i)).onRecieveData(dataPackage);
    }
  }
}
